@import "./main.scss";



//遍历主题map
@mixin themeify {

  @each $theme-name,
  $theme-map in $themes {
    //!global 把局部变量强升为全局变量
    $theme-map: $theme-map !global;

    //判断html的data-theme的属性值  #{}是sass的插值表达式
    //& sass嵌套里的父容器标识   @content是混合器插槽，像vue的slot
    [data-theme="#{$theme-name}"] & {
      @content;
    }
  }
}


//声明一个根据Key获取颜色的function
@function themed($key) {
  @if map-has-key($theme-map, $key) {
    @return map-get($theme-map, $key);
  }

  @else {
    @error "The key #{$key} isn’t defined in the map $theme-map´";
    @return null
  }
}


//获取背景颜色
@mixin background_color($color) {
  @include themeify {
    background-color: themed($color) !important;
  }
}

//获取字体颜色
@mixin color($color) {
  @include themeify {
    color: themed($color) !important;
  }
}

// 项目左上角logo颜色
@mixin logo_color($color) {
  @include themeify {
    color: themed($color) !important;
  }
}

// 页面子路由下划线的颜色
@mixin author_color($color) {
  @include themeify {
    color: themed($color) !important;
  }
}

// 边框颜色
@mixin border_color($color) {
  @include themeify {
    border-color: themed($color) !important;
  }
}


// 使用示例
.container {
  @include background_color('bk_color');
  @include color('color');
  @include logo_color('logo_color');
  @include author_color('author_color');
  @include border_color('border_color')
}
